package com.junzhiit.nengji.cms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.FullReductionService;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.FullReductionListVO;
import com.junzhiit.nengji.cms.web.vo.FullReductionVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/full/reduction")
public class FullReductionController extends BaseController {

	@Autowired
	FullReductionService fullReductionService;

	@ApiOperation(value = "获取所有活动促销活动列表")
	@RequestMapping(method = RequestMethod.GET)
	public Map<String, Object> findAll(DataTablesParamVO dtp, FullReductionListVO frlv) {
		return fullReductionService.findAll(dtp, frlv);
	}

	@ApiOperation(value = "增加满减送活动")
	@RequestMapping(method = RequestMethod.POST)
	public ResultVO addFullReduction(String sessionId,String fullReductionVO, String fullReductionConditionVO,String fullReductionGoodsVO) {
		AssertUtil.notBlank(sessionId, "sessionId is required");
		AssertUtil.notBlank(fullReductionVO, "fullReductionVO is required");
		AssertUtil.notBlank(fullReductionConditionVO, "fullReductionConditionVO is required");
		return fullReductionService.addAndEditFullReduction(fullReductionVO, fullReductionConditionVO, fullReductionGoodsVO, sessionId);
	}

	@ApiOperation(value = "删除满减活动")
	@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
	public ResultVO delete(@PathVariable String id) {
		return fullReductionService.delete(id);
	}

	@ApiOperation(value = "根据id获取满减活动信息")
	@RequestMapping(value = "/id", method = RequestMethod.GET)
	public ResultVO findById(FullReductionVO frv) {
		AssertUtil.notBlank(frv.getSessionId(), "sessionId is required.");
		return fullReductionService.findById(frv);
	}
	
	@ApiOperation(value = "修改满减送活动")
	@RequestMapping(method = RequestMethod.PUT)
	public ResultVO editFullReduction(String sessionId,String fullReductionVO, String fullReductionConditionVO,String fullReductionGoodsVO) {
		AssertUtil.notBlank(sessionId, "sessionId is required");
		AssertUtil.notBlank(fullReductionVO, "fullReductionVO is required");
		AssertUtil.notBlank(fullReductionConditionVO, "fullReductionConditionVO is required");
		return fullReductionService.addAndEditFullReduction(fullReductionVO, fullReductionConditionVO, fullReductionGoodsVO, sessionId);
	}
}
